/****************************************************************
 * 
* File Name:		PageManager.cs
 * 
 * Created:		2013/06/24
 * Original Author:	Ni Tao
 * 
 * ------------------------------------------------------------
 * MODIFICATION HISTORY
 * ------------------------------------------------------------
 * When			Who		Why
 * ------------------------------------------------------------
 * 
 *
 ****************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Xml;
using System.IO;
//using Besture.CDC.Phoebus.Common.Exception;

namespace Besture.Common.Definition
{
    /// <summary>
    /// Web page manager class
    /// </summary>
    public class PageManager
    {
        public static Hashtable hashPages = new Hashtable();
        /// <summary>
        /// Initializing method
        /// </summary>
        public static void initialize()
        {

            string lsTmpElementName = "";
            String strFilePath = AppSettings.GetPageConfigPath();
            System.Xml.XmlTextReader loLoadSetting = new XmlTextReader(strFilePath);
            PageEntity pageEntity=new PageEntity();
            while (loLoadSetting.Read())
            {
                switch (loLoadSetting.NodeType)
                {
                    case XmlNodeType.Element:
                        lsTmpElementName = loLoadSetting.Name;
                        if (lsTmpElementName.Equals("page"))
                        {
                            pageEntity = new PageEntity();
                        }
                        break;
                    case XmlNodeType.Text:
                        if (lsTmpElementName.Equals("id"))
                        {
                            pageEntity.Id = loLoadSetting.Value;
                            hashPages.Add(pageEntity.Id, pageEntity);
                        }
                        if (lsTmpElementName.Equals("name"))
                        {
                            pageEntity.Name = loLoadSetting.Value;
                        }
                        if (lsTmpElementName.Equals("path"))
                        {
                            pageEntity.Path = loLoadSetting.Value;
                        }
                        if (lsTmpElementName.Equals("roles"))
                        {
                            pageEntity.Roles = loLoadSetting.Value;
                        }
                        break;
                }
            }

        }
        /// <summary>
        /// Get the page with the page id.
        /// </summary>
        /// <param name="strId">Page id</param>
        /// <returns>Page entity object</returns>
        public static PageEntity getPage(string strId)
        {
            if (hashPages[strId] != null)
            {
                return (PageEntity)hashPages[strId];
            }
            else
            {
                return null;
            }
        }

    }
}
